package weaver.splittable.db;

import weaver.splittable.db.mysql.STMysqlCreateIndexUtil;
import weaver.splittable.db.mysql.STMysqlCreateTableUtil;
import weaver.splittable.db.mysql.STMysqlCreateTriggerUtil;
import weaver.splittable.db.mysql.STMysqlSyncSqlUtil;
import weaver.splittable.db.oracle.STOracleCreateIndexUtil;
import weaver.splittable.db.oracle.STOracleCreateTableUtil;
import weaver.splittable.db.oracle.STOracleCreateTriggerUtil;
import weaver.splittable.db.oracle.STOracleSyncSqlUtil;
import weaver.splittable.db.sqlserver.STSqlserverCreateIndexUtil;
import weaver.splittable.db.sqlserver.STSqlserverCreateTableUtil;
import weaver.splittable.db.sqlserver.STSqlserverCreateTriggerUtil;
import weaver.splittable.db.sqlserver.STSqlserverSyncSqlUtil;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class STDBSupport {

    public static final String ORACLE = "oracle";
    public static final String SQLSERVER = "sqlserver";
    public static final String MYSQL = "mysql";

    private static Set<String> SUPPORT_DB = new HashSet<>();

    private static Map<String, STCreateIndexUtil> createIndexUtils = new HashMap<>();
    private static Map<String, STCreateTableUtil> createTableUtils = new HashMap<>();
    private static Map<String, STCreateTriggerUtil> createTriggerUtils = new HashMap<>();
    private static Map<String, STSyncClearSqlUtil> syncSqlUtils = new HashMap<>();

    static {

        SUPPORT_DB.add(ORACLE);
        SUPPORT_DB.add(SQLSERVER);
        SUPPORT_DB.add(MYSQL);

        // Oracle
        createIndexUtils.put(ORACLE, new STOracleCreateIndexUtil());
        createTableUtils.put(ORACLE, new STOracleCreateTableUtil());
        createTriggerUtils.put(ORACLE, new STOracleCreateTriggerUtil());
        syncSqlUtils.put(ORACLE, new STOracleSyncSqlUtil());

        // sqlserver
        createIndexUtils.put(SQLSERVER, new STSqlserverCreateIndexUtil());
        createTableUtils.put(SQLSERVER, new STSqlserverCreateTableUtil());
        createTriggerUtils.put(SQLSERVER, new STSqlserverCreateTriggerUtil());
        syncSqlUtils.put(SQLSERVER, new STSqlserverSyncSqlUtil());

        // mysql
        createIndexUtils.put(MYSQL, new STMysqlCreateIndexUtil());
        createTableUtils.put(MYSQL, new STMysqlCreateTableUtil());
        createTriggerUtils.put(MYSQL, new STMysqlCreateTriggerUtil());
        syncSqlUtils.put(MYSQL, new STMysqlSyncSqlUtil());

    }

    public static boolean isSupport(String dbType) {
        return SUPPORT_DB.contains(dbType);
    }

    public static STCreateIndexUtil getCreateIndexUtil(String dbType) {
        return createIndexUtils.get(dbType);
    }

    public static STCreateTableUtil getCreateTableUtil(String dbType) {
        return createTableUtils.get(dbType);
    }

    public static STCreateTriggerUtil getCreateTriggerUtil(String dbType) {
        return createTriggerUtils.get(dbType);
    }

    public static STSyncClearSqlUtil getSyncSqlUtil(String dbType) {
        return syncSqlUtils.get(dbType);
    }

}
